/* **********************************************************************************
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* This source code is subject to terms and conditions of the Shared Source License
* for DSL Editor PowerToy. A copy of the license can be found in the License.htm file
* at the root of this distribution. If you can not locate the Shared Source License
* for DSL Editor PowerToy, please obtain a copy from: http://www.codeplex.com/dsltreegrideditor/Project/License.aspx.
* By using this source code in any fashion, you are agreeing to be bound by
* the terms of the Shared Source License for DSL Editor PowerToy.
*
* You must not remove this notice, or any other, from this software.
*
* **********************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Text.RegularExpressions;

namespace DslEditorPowerToy.Recipes.Converters
{
    public class RelativeFolderPathConverter : StringConverterBase
    {
        private Regex _expression = new Regex(@"^([a-zA-Z0-9_]+)(\\[a-zA-Z0-9_]+)*$");

        #region Public Methods
        public override bool IsValid(ITypeDescriptorContext context, object value)
        {
            if (value is string)
            {
                if (0 == ((string)value).Length)
                    return true;
                else
                    return this._expression.IsMatch((string)value);
            }
            return base.IsValid(context, value);
        }
        #endregion
    }

}
